package main

import "fmt"

type Books struct {
	title   string
	author  string
	subject string
	book_id int
}

func main() {
	//创建一个新的结构体
	fmt.Println(Books{"Go语音", "www.baidu.com", "Go语言教程", 1008611})

	//也可以使用key -> value格式
	fmt.Println(Books{title: "Go语言", author: "宋发元", subject: "Go语言教程", book_id: 12113133})
	fmt.Println(Books{title: "Go语言", author: "宋发元"})

	println("===============================")
	/* 声明 Book1 为 Books 类型 */
	var book1 Books
	/* 声明 Book2 为 Books 类型 */
	var book2 Books

	//book1描述
	book1.title = "Java语言"
	book1.author = "宋发元"
	book1.subject = "Java教程"
	book1.book_id = 29302930293
	//book2描述
	book2.title = "php语言"
	book2.author = "宋发元"
	book2.subject = "php教程"
	book2.book_id = 29302930234

	//打印book1信息
	fmt.Printf("book 1 title : %s\n", book1.title)
	fmt.Printf("book 1 author : %s\n", book1.author)
	fmt.Printf("book 1 subject : %s\n", book1.subject)
	fmt.Printf("book 1 book_id : %d\n", book1.book_id)

	//打印book2信息
	fmt.Printf("book 2 title : %s\n", book2.title)
	fmt.Printf("book 2 author : %s\n", book2.author)
	fmt.Printf("book 2 subject : %s\n", book2.subject)
	fmt.Printf("book 2 book_id : %d\n", book2.book_id)
	println("===============================")

	//打印信息---结构体作为函数参数
	printBook(book1)
	printBook(book2)
	println("===============================")
	printBook2(&book1)
	printBook2(&book2)
}

// 打印book信息
func printBook2(books *Books) {
	fmt.Printf("book title : %s\n", books.title)
	fmt.Printf("book author : %s\n", books.author)
	fmt.Printf("book subject : %s\n", books.subject)
	fmt.Printf("book book_id : %d\n", books.book_id)
}

// 打印book信息
func printBook(books Books) {
	fmt.Printf("book title : %s\n", books.title)
	fmt.Printf("book author : %s\n", books.author)
	fmt.Printf("book subject : %s\n", books.subject)
	fmt.Printf("book book_id : %d\n", books.book_id)
}
